const Mock = require('mockjs')

const data = Mock.mock({
    'commoditys|10': [{
        id: '@increment',
        name: "山楂",
        url: "@image('200x100', '#4A7BF7', 'Hello')",
        "price|1-100": 100,
        one: '石榴',
        two: "苹果",
    }]
})

// var obj = {
//     code: 2000,
//     data: data.news
// }

// console.log(obj);


// console.log(data);

function searchCommodityByName(name) {
    var searchRes = []
    data.commoditys.forEach(element => {
        if (element.name == name) {
            searchRes.push(element)
        }
    });
    return searchRes;
}

module.exports = [
    //getAllUser 
    {
        url: '/admin/getAllCommodity',
        type: 'get',
        response: config => {
            return {
                code: 20000,
                data: data.commoditys
            }
        }
    },
    {
        url: '/admin/searchCommodityByName',
        type: 'post',
        response: config => {
            let { name } = config.query
            return {
                code: 20000,
                data: searchCommodityByName(name)
            }
        }
    },
    {
        url: '/admin/delCommodityById',
        type: 'post',
        response: config => {
            let { id } = config.query
            return {
                code: 20000,
                data: "success"
            }
        }
    }
]